<?php

class Document extends CI_Model {

    function index() {
        $q = $this->db->get('document');
        return $q;
    }

    function show($id) {
        $this->db->where('id', $id);
        $q = $this->db->get('document');
        return $q;
    }

    function edit($id) {
        $this->db->where('id', $id);
        $q = $this->db->get('document');
        return $q;
    }

    function confirm($id) {
        $data = array(
            'status' => 1
        );
        $this->db->where('id', $id);
        $this->db->update('document', $data);
        redirect('documents/index');
    }

    function upload($title, $file) {
        $data = array(
            'title' => $title,
            'file' => $file,
        );
        $this->db->insert('document', $data);
        redirect('documents/index');
    }

    function update($title, $file) {
        if ($file == null) {
            $data = array(
                'title' => $title,
            );
            $this->db->update('document', $data);
            redirect('documents/index');
        } else {
            $data = array(
                'title' => $title,
                'file' => $file,
            );
            $this->db->update('document', $data);
            redirect('documents/index');
        }
    }

    function delete($id, $file) {
        $this->db->where('id', $id);
        $this->db->delete('document');
        return true;
    }

}

?>
